package com.kgcx.organization.controller;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.organization.domain.City;
import com.kgcx.organization.service.CityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "城市接口", tags = "城市接口")
@RestController
@RequestMapping("city")
public class CityController extends BaseController {
    @Autowired
    private CityService cityService;

    @ApiOperation(value = "查询城市", httpMethod = "GET", notes = "这是用来查询城市的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "城市ID", required = true, paramType = "query", dataType = "String", dataTypeClass = Long.class),
    })
    @GetMapping("getCity")
    public ReturnData<City> getCity(@RequestParam Long kid) {
        return new ReturnData<>(cityService.getCity(kid));
    }

    @ApiOperation(value = "查询城市", httpMethod = "GET", notes = "这是用来查询城市的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "type", value = "类型：1=有机场的城市，2=有高铁站的城市", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("getCityList")
    public ReturnData<List<City>> getCityList() {
        RequestData requestData = this.getRequestData();
        List<City> cityList = cityService.getCityList(requestData);
        return new ReturnData<>(cityList);
    }

    @ApiOperation(value = "新增城市", httpMethod = "POST", notes = "这是用来新增城市的接口")
    @PostMapping("addCity")
    public ReturnData addCity(@RequestBody City city) {
        cityService.addCity(city);
        return new ReturnData();
    }

    @ApiOperation(value = "修改城市", httpMethod = "POST", notes = "这是用来修改城市的接口")
    @PostMapping("updateCity")
    public ReturnData updateCity(@RequestBody City city) {
        cityService.updateCity(city);
        return new ReturnData();
    }

    @ApiOperation(value = "删除城市", httpMethod = "POST", notes = "这是用来删除城市的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "用户ID", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @PostMapping("removeCity")
    public ReturnData removeCity(@RequestParam Long kid) {
        cityService.removeCity(kid);
        return new ReturnData();
    }
}
